using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExplosionEffect : MonoBehaviour
{
    Animator anim;
    AudioSource audioSource;
    GameManager gm;
    SpriteRenderer spriteRenderer;
    private void Start()
    {
        gm=FindObjectOfType<GameManager>();
        anim = GetComponent<Animator>();
        audioSource = GetComponent<AudioSource>();
        spriteRenderer = GetComponent<SpriteRenderer>();
    }
    void End()
    {
        StartCoroutine(IEnd());
        gm.animaCount--;
    }
    IEnumerator IEnd()
    {
        spriteRenderer.enabled = false;
        while (audioSource.isPlaying)
        {
            yield return null;
        }
        ObjectsPool.Instance.Push(gameObject);
    }
    public void Play()
    {
        if(anim!=null)anim.Play("play");
        if(audioSource!=null)audioSource.Play();
        if(spriteRenderer!=null)spriteRenderer.enabled = true;
    }
}
